package action;


import servise.userRegisterService;
import dao.UserDao;
import dao.UserRegisterDao;

public class UserRegisterAction {
	private String userName;
	private String password;
	private Integer sex;
	private Float weight;
	private Float height;
	UserRegisterDao userRegisterDao = new UserRegisterDao();
	public UserRegisterAction(String userName, String password, Integer sex,
			Float weight, Float height) {
		super();
		this.userName = userName;
		this.password = password;
		this.sex = sex;
		this.weight = weight;
		this.height = height;
	}
	//判断所要注册的用户名是否存在，存在返回true，不存在返回false
	public boolean checkExist(){
		String sql = "select * from userInfo where username='"+userName+"'";
		userRegisterService userRegisterService = userRegisterDao.selectItem(sql);
		if(userRegisterService.getUserName()==null){
			return false;
		}else{
			return true;
		}
	}
	//判断为完是否存在后，若存在则返回，否则就执行插入操作
	public int addUser(){
		if(checkExist()){
			return 2;          //用户名存在
		}else{
			String sql = "insert into userInfo(username,password,sex,weight,height) " +
					"values('"+userName+"','"+password+"',"+sex+","+weight+","+height+")";
			return userRegisterDao.addItem(sql);   //返回1时表示插入成功，为0时表示插入失败
		}
	}

}
